<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Models\Classes
 *
 * @property-read \App\Models\Category $category
 * @property-read \App\Models\Course $course
 * @property-read mixed $price
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Classes newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Classes newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Classes onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Classes query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Classes withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Classes withoutTrashed()
 * @mixin \Eloquent
 * @property-read mixed $cover
 * @property-read mixed $url
 */
class Classes extends Base
{
    use SoftDeletes;
    protected $dates = ['deleted_at'];

    protected $fillable = ['category_id', 'course_id', 'name', 'price', 'url', 'cover'];

    protected $table = 'classes';

    public function course()
    {
        return $this->belongsTo(Course::class);
    }

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function getCoverAttribute($val)
    {
        if (substr($val,0,4) != 'http') return config('app.url') . $val;
        return $val;
    }
    public function getUrlAttribute($val)
    {
        if (substr($val,0,4) != 'http') return config('app.url') . $val;
        return $val;
    }
}
